package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.domain.dto.AddDefTeamMemberDTO;
import com.ruoyi.system.domain.dto.DefTeamMemberImportDTO;
import com.ruoyi.system.domain.dto.UserWithDrillDTO;
import com.ruoyi.system.domain.vo.TeamUserDetailVO;
import com.ruoyi.system.domain.vo.UserNoRoleVO;
import com.ruoyi.system.domain.vo.UserWithDrillVO;
import io.swagger.models.auth.In;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DefTeamMember;
import com.ruoyi.system.service.IDefTeamMemberService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 队伍队员关系Controller
 * 
 * @author ruoyi
 * @date 2024-10-09
 */
@RestController
@RequestMapping("/system/member")
public class DefTeamMemberController extends BaseController
{
    @Autowired
    private IDefTeamMemberService defTeamMemberService;

    /**
     * 查询队伍队员关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:member:list')")
    @GetMapping("/list")
    public TableDataInfo list(DefTeamMember defTeamMember)
    {
        startPage();
        List<DefTeamMember> list = defTeamMemberService.selectDefTeamMemberList(defTeamMember);
        return getDataTable(list);
    }

    /**
     * 导出队伍队员关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:member:export')")
    @Log(title = "队伍队员关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DefTeamMember defTeamMember)
    {
        List<DefTeamMember> list = defTeamMemberService.selectDefTeamMemberList(defTeamMember);
        ExcelUtil<DefTeamMember> util = new ExcelUtil<DefTeamMember>(DefTeamMember.class);
        util.exportExcel(response, list, "队伍队员关系数据");
    }

    /**
     * 获取队伍队员关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:member:query')")
    @GetMapping(value = "/{teamId}")
    public AjaxResult getInfo(@PathVariable("teamId") Integer teamId)
    {
        return success(defTeamMemberService.selectDefTeamMemberByTeamId(teamId));
    }

    /**
     * 新增队伍队员关系
     */
    @PreAuthorize("@ss.hasPermi('system:member:add')")
    @Log(title = "队伍队员关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddDefTeamMemberDTO defTeamMember)
    {
        return toAjax(defTeamMemberService.insertDefTeamMember(defTeamMember));
    }

    /**
     * 修改队伍队员关系
     */
    @PreAuthorize("@ss.hasPermi('system:member:edit')")
    @Log(title = "队伍队员关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AddDefTeamMemberDTO defTeamMember)
    {
        return toAjax(defTeamMemberService.updateDefTeamMember(defTeamMember));
    }

    /**
     * 删除队伍队员关系
     */
    @PreAuthorize("@ss.hasPermi('system:member:remove')")
    @Log(title = "队伍队员关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userId}")
    public AjaxResult remove(@PathVariable Integer userId)
    {
        return toAjax(defTeamMemberService.deleteDefTeamMemberByUserId(userId));
    }

    /**
     * 当前演练队员
     */
    @PostMapping("/user-with-drill")
    public TableDataInfo userWithDrill(@RequestBody UserWithDrillDTO dto)
    {
        startPage();
        List<UserWithDrillVO> list = defTeamMemberService.userWithDrill(dto);
        return getDataTable(list);
    }

    /**
     * 导入队员
     */
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, Long roleId) throws Exception
    {
        ExcelUtil<DefTeamMemberImportDTO> util = new ExcelUtil<>(DefTeamMemberImportDTO.class);
        List<DefTeamMemberImportDTO> userList = util.importExcel(file.getInputStream());
        return success(defTeamMemberService.importData(userList, roleId));
    }

    @PostMapping("/team-user-detail/{userId}")
    public AjaxResult teamUserDetail(@RequestBody Long userId)
    {
        TeamUserDetailVO vo= defTeamMemberService.teamUserDetail(userId);
        return  success(vo);
    }

    @PostMapping("/user-no-role")
    public TableDataInfo userNoRole()
    {
        List<UserNoRoleVO> vo= defTeamMemberService.userNoRole();
        return  getDataTable(vo);
    }

}
